package com.heying.springcore.aop.transaction;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class TestJdbc {

    public static void main(String[] args) throws ClassNotFoundException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/test02?userSSL=false&useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2B8";
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(url, "root","");
            String insert = "insert into userinfo values(?,?)";
            PreparedStatement pstmt = conn.prepareStatement(insert);
            pstmt.setInt(1, 1);
            pstmt.setString(2, "aaa");
            pstmt.executeUpdate();
//            conn.commit();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
//            try {
//                conn.rollback();
//            } catch (SQLException e) {
//                e.printStackTrace();
//            }
        }finally {
            if (null != conn){
                try {
                    conn.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        }

    }
}
